package de.baumann.browser.activitys.node

import android.content.Context
import android.content.Intent
import android.support.v7.widget.LinearLayoutManager
import de.baumann.browser.R
import de.baumann.browser.adapter.RequestJoinListAdapter
import de.baumann.browser.api.net.vo.JoinApp
import de.baumann.browser.base.BaseOdinActivity
import de.baumann.browser.iview.IRequestJoinView
import de.baumann.browser.present.RequestJoinPresenter
import de.baumann.browser.utils.getBoolean
import kotlinx.android.synthetic.main.activity_request_join.*
import kotlinx.android.synthetic.main.include_tool_bar.*

/**
 *@author:
 *@date:2019/9/26 10:33
 *@discription: 申请列表
 */
@Deprecated("5.0.0版本之后活动结束，不再适用")
class RequestJoinActivity : BaseOdinActivity<IRequestJoinView, RequestJoinPresenter>(), IRequestJoinView {

    companion object {
        fun startRequestJoinActivity(context: Context, nodeId: String) {
            context.startActivity(Intent(context, RequestJoinActivity::class.java).apply {
                putExtra("nodeId", nodeId)
            })
        }
    }

    private lateinit var mJoinListAdapter: RequestJoinListAdapter

    override fun getTitleText(): String {
        return "申请列表"
    }

    override fun getLayout(): Int {
        return R.layout.activity_request_join
    }

    override fun initView() {
        initToolbar(commToolBar,commTitle)
        rvRequestJoin.layoutManager = LinearLayoutManager(mContext)
        mJoinListAdapter = RequestJoinListAdapter(R.layout.item_request_join)
        rvRequestJoin.adapter = mJoinListAdapter
        mJoinListAdapter.setOnItemClickListener { adapter, view, position ->
            val joinApp = adapter.getItem(position) as JoinApp
            if (joinApp.status == 0) {
                JoinVerifyActivity.startJoinVerifyActivity(mContext,joinApp.applyId)
            }
        }
    }

    override fun createPresenter(): RequestJoinPresenter {
        return RequestJoinPresenter()
    }

    override fun createView(): IRequestJoinView {
        return this
    }

    override fun initData() {
        presenter.requestJoinList()
    }

    override fun onRestart() {
        super.onRestart()
        if (getBoolean("isVerifyAction")) {
            presenter.requestJoinList()
        }
    }


    override fun getNodeId(): String {
        return intent.getStringExtra("nodeId")
    }

    override fun setJoinAppList(joins: List<JoinApp>?) {
        mJoinListAdapter.setNewData(joins)
    }

}
